import Vue from 'vue'
import Vuex from 'vuex'
import createPersistedState from 'vuex-persistedstate'

Vue.use(Vuex)

const store = new Vuex.Store({
	plugins:[createPersistedState()],
	state:{
		token:'',
		info:{
			id:'',
			name:'',
			username:''
		},
		zones:[]
	},
	mutations:{
		setToken(state,token){
			state.token = token
		},
		setInfo(state,info){
			state.info.id = info.id
			state.info.name = info.name
			state.info.username = info.username
		},
		setZones(state,zones){
			state.zones = zones
		},
		removeToken(state){
			state.token = ''
		},
		removeInfo(state){
			state.info.id = ''
			state.info.name = ''
			state.info.username = ''
		}
	},
	getters:{
		token(state){
			return state.token
		},
		info(state){
			return state.info
		},
		zones(state){
			return state.zones
		}
	}
})

export default store